<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('客户端报文修改')"/>
</head>
<body>
<form action="" class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">主键</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="id"
                               th:value="${simMsgRecord.id}" placeholder="请输入主键" type="text">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="busiType"
                               th:value="${simMsgRecord.busiType}" placeholder="请输入类型" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">渠道</label>
                    <div class="layui-input-block">
                        <select id="channelNo" dict-code="msg_channel_no" lay-verify="required" name="channelNo"
                                default-value="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">报文编号</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="msgCode"
                               th:value="${simMsgRecord.msgCode}"
                               placeholder="请输入报文编号" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">报文名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="msgName"
                               th:value="${simMsgRecord.msgName}"
                               placeholder="请输入报文名称" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">通信协议</label>
                    <div class="layui-input-block">
                        <select id="protocol" dict-code="msg_protocol_name" lay-verify="required" name="protocol"
                                default-value="" lay-filter="protocol">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">报文编码</label>
                    <div class="layui-input-block">
                        <select id="charsetName" dict-code="msg_charset_name" lay-verify="required" name="charsetName"
                                default-value="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">报文头策略</label>
                    <div class="layui-input-block">
                        <select id="headStrategy" dict-code="msg_head_strategy" lay-verify="required"
                                name="headStrategy"
                                default-value="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="httpMethodItem">
                    <label class="layui-form-label">Http方法</label>
                    <div class="layui-input-block">
                        <select id="httpMethod" dict-code="msg_http_method" lay-verify="required" name="httpMethod"
                                default-value="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">报文内容</label>
                    <div class="layui-input-block">
                    <textarea class="layui-textarea" style="min-height: 200px" lay-verify="required"
                              name="msgContent" th:text="${simMsgRecord.msgContent}"
                              placeholder="请输入报文内容"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                    <textarea class="layui-textarea" name="remark" th:text="${simMsgRecord.remark}"
                              placeholder="请输入描述"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="msg-update" lay-submit=""
                    type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="pear-btn pear-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    $('#channelNo').attr("default-value", [[${simMsgRecord.channelNo}]]);
    $('#protocol').attr("default-value", [[${simMsgRecord.protocol}]]);
    $('#charsetName').attr("default-value", [[${simMsgRecord.charsetName}]]);
    $('#headStrategy').attr("default-value", [[${simMsgRecord.headStrategy}]]);
    $('#httpMethod').attr("default-value", [[${simMsgRecord.httpMethod}]]);

    layui.use(['form', 'jquery', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        if ('HTTP'.localeCompare($('#protocol').val(), undefined, {sensitivity: 'base'}) === 0) {
            // HTTP协议
            $("#httpMethodItem").show();
        } else {
            $("#httpMethodItem").hide();
        }
        form.on('select(protocol)', function (data) {
            if ('HTTP'.localeCompare(data.value, undefined, {sensitivity: 'base'}) === 0) {
                // HTTP协议
                $("#httpMethodItem").show();
            } else {
                $("#httpMethodItem").hide();
            }
        });

        form.on('submit(msg-update)', function (data) {
            $.ajax({
                url: '/sim/msg/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("msg-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>